package com.eunion.web.common.vo;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.http.HttpStatus;

/**
 * 主要使用200,500，表示OK与失败.
 * <p>
 * // 1xx Informational
 * <p>
 * CONTINUE(100, "Continue"),
 * <p>
 * SWITCHING_PROTOCOLS(101, "Switching Protocols"),
 * <p>
 * PROCESSING(102, "Processing"),
 * <p>
 * CHECKPOINT(103, "Checkpoint"),
 * <p>
 * // 2xx Success
 * <p>
 * OK(200, "OK"),
 * <p>
 * CREATED(201, "Created"),
 * <p>
 * ACCEPTED(202, "Accepted"),
 * <p>
 * NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
 * <p>
 * NO_CONTENT(204, "No Content"),
 * <p>
 * RESET_CONTENT(205, "Reset Content"),
 * <p>
 * PARTIAL_CONTENT(206, "Partial Content"),
 * <p>
 * MULTI_STATUS(207, "Multi-Status"),
 * <p>
 * ALREADY_REPORTED(208, "Already Reported"),
 * <p>
 * IM_USED(226, "IM Used"),
 * <p>
 * MULTIPLE_CHOICES(300, "Multiple Choices"),
 * <p>
 * MOVED_PERMANENTLY(301, "Moved Permanently"),
 * <p>
 * FOUND(302, "Found"),
 * <p>
 * MOVED_TEMPORARILY(302, "Moved Temporarily"),
 * <p>
 * SEE_OTHER(303, "See Other"),
 * <p>
 * NOT_MODIFIED(304, "Not Modified"),
 * <p>
 * USE_PROXY(305, "Use Proxy"),
 * <p>
 * TEMPORARY_REDIRECT(307, "Temporary Redirect"),
 * <p>
 * PERMANENT_REDIRECT(308, "Permanent Redirect"),
 * <p>
 * BAD_REQUEST(400, "Bad Request"),
 * <p>
 * UNAUTHORIZED(401, "Unauthorized"),
 * <p>
 * PAYMENT_REQUIRED(402, "Payment Required"),
 * <p>
 * FORBIDDEN(403, "Forbidden"),
 * <p>
 * NOT_FOUND(404, "Not Found"),
 * <p>
 * METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
 * <p>
 * NOT_ACCEPTABLE(406, "Not Acceptable"),
 * <p>
 * PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
 * <p>
 * REQUEST_TIMEOUT(408, "Request Timeout"),
 * <p>
 * CONFLICT(409, "Conflict"),
 * <p>
 * GONE(410, "Gone"),
 * <p>
 * LENGTH_REQUIRED(411, "Length Required"),
 * <p>
 * PRECONDITION_FAILED(412, "Precondition Failed"),
 * <p>
 * PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
 * <p>
 * REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
 * <p>
 * URI_TOO_LONG(414, "URI Too Long"),
 * <p>
 * REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),
 * <p>
 * UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
 * <p>
 * REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
 * <p>
 * EXPECTATION_FAILED(417, "Expectation Failed"),
 * <p>
 * I_AM_A_TEAPOT(418, "I'm a teapot"),
 * <p>
 * INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"),
 * <p>
 * METHOD_FAILURE(420, "Method Failure"),
 * <p>
 * DESTINATION_LOCKED(421, "Destination Locked"),
 * <p>
 * UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
 * <p>
 * LOCKED(423, "Locked"),
 * <p>
 * FAILED_DEPENDENCY(424, "Failed Dependency"),
 * <p>
 * UPGRADE_REQUIRED(426, "Upgrade Required"),
 * <p>
 * PRECONDITION_REQUIRED(428, "Precondition Required"),
 * <p>
 * TOO_MANY_REQUESTS(429, "Too Many Requests"),
 * <p>
 * REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large" ),
 * <p>
 * INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
 * <p>
 * NOT_IMPLEMENTED(501, "Not Implemented"),
 * <p>
 * BAD_GATEWAY(502, "Bad Gateway"),
 * <p>
 * SERVICE_UNAVAILABLE(503, "Service Unavailable"),
 * <p>
 * GATEWAY_TIMEOUT(504, "Gateway Timeout"),
 * <p>
 * HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"),
 * <p>
 * VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
 * <p>
 * INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
 * <p>
 * LOOP_DETECTED(508, "Loop Detected"),
 * <p>
 * BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
 * <p>
 * NOT_EXTENDED(510, "Not Extended"),
 * <p>
 * NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
 * 
 * 
 * @version 2015-8-26
 */
public class WebStatus {

	/**
	 * web响应状态码,参考org.springframework.http.HttpStatus 或本类注释上doc .
	 */
	private int code = HttpStatus.OK.value();

	/**
	 * 信息，一般指错误信息.
	 */
	private String message;

	public WebStatus() {}

	/**
	 * get web响应状态码参考org.springframework.http.HttpStatus 或本类注释上doc . .
	 * 
	 * @return the code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * set web响应状态码参考org.springframework.http.HttpStatus 或本类注释上doc ..
	 * 
	 * @param code
	 *            the code to set
	 * @return WebStatus 对象
	 */
	public WebStatus setCode(int code) {
		this.code = code;
		return this;
	}

	/**
	 * set web响应状态码参考org.springframework.http.HttpStatus 或本类注释上doc ..
	 * 
	 * @return WebStatus 对象
	 */
	public WebStatus setCodeOK() {
		this.code = HttpStatus.OK.value();
		return this;
	}

	/**
	 * set web响应状态码参考org.springframework.http.HttpStatus 或本类注释上doc ..
	 * 
	 * @return WebStatus 对象
	 */
	public WebStatus setCodeOK(String msseage) {
		this.code = HttpStatus.OK.value();
		this.message = msseage;
		return this;
	}

	/**
	 * set web响应状态码参考org.springframework.http.HttpStatus 或本类注释上doc ..
	 * 
	 * @return WebStatus 对象
	 */
	public WebStatus setCodeError() {
		return setCodeError("服务器错误!");
	}

	/**
	 * set web响应状态码参考org.springframework.http.HttpStatus 或本类注释上doc ..
	 * 
	 * @param message
	 *            INTERNAL_SERVER_ERROR 的信息.
	 * @return WebStatus 对象
	 */
	public WebStatus setCodeError(String message) {
		this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
		this.message = message;
		return this;
	}

	/**
	 * get 信息，一般指错误信息. .
	 * 
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * set 信息，一般指错误信息..
	 * 
	 * @param message
	 *            the message to set
	 * @return WebStatus 对象
	 */
	public WebStatus setMessage(String message) {
		this.message = message;
		return this;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
